﻿namespace NDK.Motion.Card
{
    #region enum
    /// <summary>
    /// 0: Disable, 1: Standard mode, 2: Gantry mode.
    /// </summary>
    public enum GEAR_MODE
    {
        Disable = 0,
        Standard = 1,
        Gantry = 2
    }
    /// <summary>
    /// 运动方向
    /// </summary>
    public enum DIR_ENUM
    {
        Positive = 0,
        Negative
    };

    public enum PulsOutMode
    {
        PulseDir = 0,
        PulsePulse
    };

    /// <summary>
    /// 
    /// </summary>
    public enum SWITCH_ENUM
    {
        Disable = 0,
        Reserved=1,
        Enable = 2
    }
   
    public enum STOP_TYPE
    {
        JOG_STOP,
        DEC_STOP,
        EMG_STOP
    }
    public enum PRA_SF_ENUM
    {
        T_CURVE = 0,
        S_CURVE = 1
    }
    public enum PRA_HOME_ENUM
    {
        HOME_MODE_ORG = 0,
        HOME_MODE_EL = 1,
        HOME_MODE_EZ = 2,
        HOME_MODE_ELEZ = 3
    }
    public enum PRA_OPTION_ENUM
    {
        Absolute = 0,
        Relative = 1
    }
    public enum PAR_AMETER_TABLE_ENUM
    {
        MIO_ALM = 0,// Servo alarm.
        MIO_PEL = 1,// Positive end limit.
        MIO_MEL = 2,//Negative end limit.
        MIO_ORG = 3,// ORG =Home
        MIO_EMG = 4,// Emergency stop
        MIO_EZ = 5,// EZ.
        MIO_INP = 6,// In position.
        MIO_SVON = 7,// Servo on signal.
        MIO_RDY = 8,// Ready.
        MIO_WARN = 9,// Warning.
        MIO_ZSP = 10,// Zero speed.
        MIO_SPEL = 11,// Soft positive end limit.
        MIO_SMEL = 12,// Soft negative end limit.
        MIO_TLC = 13,//Torque is limited by torque limit value.
        MIO_ABSL = 14,// Absolute position lost.
        MIO_STA = 15,// External start signal.
        MIO_PSD = 16,// Positive slow down signal
        MIO_MSD = 17,// Negative slow down signal
        MTS_CSTP = 0,// Command stop signal.
        MTS_VM = 1,//At maximum velocity.
        MTS_ACC = 2,//In acceleration.
        MTS_DEC = 3,// In deceleration.
        MTS_DIR = 4,// LastMoving direction.
        MTS_NSTP = 5,// Normal stop(Motion done.
        MTS_HMV = 6,//In home operation.
        MTS_SMV = 7,//Single axis move relative, absolute, velocity move.
        MTS_LIP = 8,//Linear interpolation.
        MTS_CIP = 9,//Circular interpolation.
        MTS_VS = 10,// At start velocity.
        MTS_PMV = 11,// Point table move.
        MTS_PDW = 12,// Point table dwell move.
        MTS_PPS = 13,// Point table pause state.
        MTS_SLV = 14,// Slave axis move.
        MTS_JOG = 15,// Jog move.
        MTS_ASTP = 16,// Abnormal stop.
        MTS_SVONS = 17,// Servo off stopped.
        MTS_EMGS = 18,// EMG / SEMG stopped.
        MTS_ALMS = 19,// Alarm stop.
        MTS_WANS = 20,// Warning stopped.
        MTS_PELS = 21,// PEL stopped.
        MTS_MELS = 22,// MEL stopped.
        MTS_ECES = 23,//Error counter check level reaches and stopped.
        MTS_SPELS = 24,//Soft PEL stopped.
        MTS_SMELS = 25,//Soft MEL stopped.
        MTS_STPOA = 26,// Stop by others axes.
        MTS_GDCES = 27,// Gantry deviation error level reaches and stopped.
        MTS_GTM = 28,// Gantry mode turn on.
        MTS_PAPB = 29,//Pulsar mode turn on.
        MTS_MDN = 5,// Motion done. 0: In motion, 1: Motion done ( It could be abnormal stop)
        MTS_WAIT = 10,// Axis is in waiting state. ( Wait move trigger )
        MTS_PTB = 11,// Axis is in point buffer moving. ( When this bit on, MDN and ASTP will be cleared )
        MTS_MagnificationD = 17,// Axis (Axes) in blending moving
        MTS_PRED = 18,// Pre-distance event, 1: event arrived. The event will be clear when axis start moving 
        MTS_POSTD = 19,// Post-distance event. 1: event arrived. The event will be clear when axis start moving
        MTS_GER = 28        // 1: In

    }
    public enum PRA_DIMENSION_ENUM
    {
        Dimension_01 = 1,
        Dimension_02 = 2,
        Dimension_03 = 3,
        Dimension_04 = 4,
        Dimension_05 = 5,
        Dimension_06 = 6
    }
    public enum MOTION_STATUS_ENUM
    {
        MIO_ALM = 0,  // Servo alarm.
        MIO_PEL = 1,  //Positive end limit.
        MIO_MEL = 2,  //Negative end limit.
        MIO_ORG = 3,  // ORG =Home
        MIO_EMG = 4,  // Emergency stop
        MIO_EZ = 5,   // EZ.
        MIO_INP = 6,  // In position.
        MIO_SVON = 7, // Servo on signal.
        MIO_RDY = 8,  // Ready.
        MIO_WARN = 9, // Warning.
        MIO_ZSP = 10, // Zero speed.
        MIO_SPEL = 11, // Soft positive end limit.
        MIO_SMEL = 12, // Soft negative end limit.
        MIO_TLC = 13,  // Torque is limited by torque limit value.
        MIO_ABSL = 14, // Absolute position lost.
        MIO_STA = 15,  //External start signal.
        MIO_PSD = 16,  //Positive slow down signal
        MIO_MSD = 17,  // Negative slow down signal

        //Motion status bit number define.
        MTS_CSTP = 0,  //Command stop signal.
        MTS_VM = 1,   // At maximum velocity.
        MTS_ACC = 2,  //In acceleration.
        MTS_DEC = 3,  // In deceleration.
        MTS_DIR = 4,  // LastMoving direction.
        MTS_NSTP = 5, // Normal stop(Motion done.
        MTS_HMV = 6,  //In home operation.
        MTS_SMV = 7,  //Single axis move relative, absolute, velocity move.
        MTS_LIP = 8,  //Linear interpolation.
        MTS_CIP = 9,  // Circular interpolation.
        MTS_VS = 10,  // At start velocity.
        MTS_PMV = 11,  // Point table move.
        MTS_PDW = 12,  // Point table dwell move.
        MTS_PPS = 13,  // Point table pause state.
        MTS_SLV = 14,  //Slave axis move.
        MTS_JOG = 15,  //Jog move.
        MTS_ASTP = 16, // Abnormal stop.
        MTS_SVONS = 17, // Servo off stopped.
        MTS_EMGS = 18,  // EMG / SEMG stopped.
        MTS_ALMS = 19,  // Alarm stop.
        MTS_WANS = 20,  //Warning stopped.
        MTS_PELS = 21,  //PEL stopped.
        MTS_MELS = 22,  //MEL stopped.
        MTS_ECES = 23,  //Error counter check level reaches and stopped.
        MTS_SPELS = 24,  // Soft PEL stopped.
        MTS_SMELS = 25,  //Soft MEL stopped.
        MTS_STPOA = 26,  // Stop by others axes.
        MTS_GDCES = 27,  //Gantry deviation error level reaches and stopped.
        MTS_GTM = 28,    //Gantry mode turn on.
        MTS_PAPB = 29  // Pulsar mode turn on.
    }
    public enum CARD_NAME_TYPE
    {
        PCI_8392 = 0,
        PCI_825x,
        PCI_8154,
        PCI_785X,
        PCI_8158,
        PCI_7856,
        ISA_DPAC1000,
        ISA_DPAC3000,
        PCI_8144,
        PCI_8258,
        PCI_8102,
        PCI_V8258,
        PCI_V8254,
        PCI_8158A,
        PCI_20408C
    }

    #endregion
 
    public interface IMotionCard:ICard
    {
        int StartAxisID { get; set; }
        int TotalAxis { get; set; }

        bool CheckMoveDone(short axisId);
        bool ClearAlarm(short axisId);
        bool GetORGStatus(short axisId);
        bool GetMELStatus(short axisId);
        bool GetPELStatus(short axisId);
        bool GetINPStatus(short axisId);
        bool GetEMGStatus(short axisId);
        bool GetALMStatus(short axisId);
        bool GetASTPStatus(short axisId);
        bool GetCSTPStatus(short axisId);
        bool GetNSTPStatus(short axisId);
        bool GetHMVStatus(short axisId);
        /// <summary>
        /// 设置指定轴当前位置为pos
        /// </summary>
        /// <param name="axisId"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        bool SetPos(int axisId, double pos);
        bool GetServoOnStatus(short axisId);
        bool GetCmdPosition(short axisId, ref double commandPosition);

        bool GetErrorPosition(short axisId, ref double errorPosition);
        bool GetFeedbackPosition(short axisId, ref double feedbackPosition);
        bool GetFeedbackVelocity(short axisId, ref double feedbackVelocity);
        bool GetMotionIoSatus(short axisId, int motionIoStatusBit);
        bool GetMotionStatus(short axisId, int motionStatusBit);
        bool GetTargetPosition(short axisId, ref double targetPosition);
        bool HomeMove(short axisId, PRA_HOME_ENUM homeMode, DIR_ENUM homeDir, PRA_SF_ENUM homeCure, double homeAcc, double homeVm, double homeVo, double homeShiftDistance, double stopDec, SWITCH_ENUM isEnableSoftLimit, double spelPos, double smelPos);
        bool InterPolationLine(int[] axisIdArray, double[] axisPosArray, PRA_OPTION_ENUM apsOption, double vm, double acc = 0.1, double dec = 0.1, PRA_SF_ENUM SF = PRA_SF_ENUM.S_CURVE);
        bool IsMoving(int axisNum);
        bool LoadParamFile(string filePath, int boardId);
        bool MoveVel(short axisId, DIR_ENUM dir, double acc, double dec, double vm, double SF = 0.5);
        void P2PMoveWait(int[] axisIdArray, double[] axisPosArray, PRA_OPTION_ENUM apsOption, double[] vm, double[] acc, double[] dec);
        void PointTableMove(int _cardId, int axis0, int axis1, double[] x, double[] y, double vm, double acc);
        bool PTPMove(short axisId, PRA_OPTION_ENUM ApsOption, double vm, double acc, double dec, double position);
        bool JogMoveStart(short axisId, DIR_ENUM apsOption, double jogVm, double jogAcc);
        bool JogMoveStop(short axisId);
        bool ServoOff(int axisId);
        bool ServoON(int axisId);

        bool StopEmg(short axisId);
        bool StopMove(short axisId, double acc);
        bool StartGear(short axisId, GEAR_MODE mode);
        bool IsHoming(int axisID);
    }
}
